<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>图书馆借阅系统 - 登录</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f0f8ff;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: #212529;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            padding: 0;
        }
        .auth-container {
            width: 100%;
            max-width: 500px;
            background-color: white;
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            padding: 40px;
        }
        .auth-title {
            font-size: 2rem;
            font-weight: bold;
            margin-bottom: 10px;
        }
        .auth-subtitle {
            font-size: 1rem;
            color: #777;
            margin-bottom: 40px;
        }
        .form-control {
            border-radius: 30px;
            padding: 15px 20px;
            margin-bottom: 20px;
            border: 1px solid #ddd;
            font-size: 1rem;
        }
        .form-control:focus {
            border-color: #4a90e2;
            box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.25);
        }
        .btn-login {
            background-color: #4a90e2;
            color: white;
            border: none;
            border-radius: 30px;
            padding: 15px 0;
            width: 100%;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .btn-login:hover {
            background-color: #3a7bc8;
        }
        .forgot-password {
            text-align: center;
            margin-top: 20px;
            color: #777;
            font-size: 0.9rem;
        }
        .forgot-password a {
            color: #4a90e2;
            text-decoration: none;
        }
    </style>
    <meta charset="utf-8">
</head>
<body>
<div class="auth-container">
    <div class="auth-title">WELCOME! 图书馆借阅系统</div>
    <div class="auth-subtitle">为你的学习之旅增添助力</div>

    <form id="login-form">
        <div class="input-group">
            <input type="text" id="username" class="form-control" placeholder="用户名" required>
        </div>
        <div class="input-group">
            <input type="password" id="password" class="form-control" placeholder="密码" required>
        </div>
        <div class="forgot-password">
            <a href="register.html" id="register-link">注册</a>
        </div>
        <button type="submit" class="btn btn-login">登录</button>
    </form>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    document.getElementById('login-form').addEventListener('submit', function(e) {
        e.preventDefault();

        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        // 发送POST请求到后端登录API
        fetch('/api/auth/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                username: username,
                password: password
            })
        })
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    alert('登录成功！');
                    window.location.href = 'index.html'; // 登录成功后跳转到主页面
                    localStorage.setItem('token', data.data); // 存储JWT Token
                } else {
                    alert('登录失败，请检查用户名和密码。');
                }
            })
            .catch(error => {
                console.error('登录请求出错:', error);
                alert('登录请求出错，请稍后再试。');
            });
    });
</script>
</body>
</html>
